package deployr.core;

import static java.text.MessageFormat.*;

import java.util.*;

import deployr.domain.*;

public class UpdateBuilder {

	private final Workspace workspace;

	private final List<IUpdate> updates = new LinkedList<IUpdate>();
	
	public UpdateBuilder(Workspace workspace) {
		this.workspace = workspace;
	}

	public UpdateBuilder scan(String path) {
		List<Metadata> someMetadata = workspace.updatesMetadata(path);
		for (Metadata metadata : someMetadata) {
			addUpdate(metadata);
		}
		return this;
	}

	private void addUpdate(Metadata metadata) {
		Update update = new Update(metadata);
		log("found update {0}", update.getPath());
		updates.add(update);
	}

	private void log(String string, String... args) {
		System.out.println(format(string, args));
	}

	public List<IUpdate> getUpdates() {
		return updates;
	}

}